package com.rtx.edi.system.usermenu.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.rtx.edi.system.usermenu.service.impl.UserPermissionServiceImpl;
import com.rtx.model.dto.response.EdiResponse;
import com.rtx.model.dto.response.userpermission.TreeResponse;
import com.rtx.model.po.entity.system.MenuPermission;
import com.rtx.model.po.entity.system.User;
import com.rtx.model.po.entity.system.UserPermission;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Controller
@Api(tags = "用户菜单授权", value = "用户菜单授权")
public class UserMenuPermissionController {

    @Autowired
    private UserPermissionServiceImpl userPermissionService;

    @ApiOperation(value = "获取用户信息", notes = "参数:username((输入姓名或用户名查询的时候传,查询列表的时候不传))")
    @RequestMapping(value = "queryAllUserList", method = RequestMethod.POST)
    @ResponseBody
    public EdiResponse queryAllUserList(@RequestBody User user) {
        return EdiResponse.success().data("data", userPermissionService.queryAllUserList(user));
    }

    /**
     * 获取树形菜单和用户选中的菜单id
     *
     * @param userPermission
     * @return
     */
    @ApiOperation(value = "获取树形和用户选中菜单", notes = "获取树形和用户选中菜单")
    @RequestMapping(value = "queryPermissionList", method = RequestMethod.POST)
    @ResponseBody
    public TreeResponse<MenuPermission> queryPermissionList(@RequestBody UserPermission userPermission) {
        return userPermissionService.queryPermissionList(userPermission);
    }

    /**
     * 删除或增加权限
     *
     * @param userPermission
     * @return
     */
    @ApiOperation(value = "删除或增加权限", notes = "删除或增加权限")
    @RequestMapping(value = "saveOrDelete", method = RequestMethod.POST)
    @ResponseBody
    public EdiResponse saveOrDelete(@RequestBody UserPermission userPermission) {
        userPermissionService.saveOrDelete(userPermission);
        return EdiResponse.success();
    }

}
